package com.cmpan.networkdisk.service;

import com.cmpan.networkdisk.dao.UserMapper;
import com.cmpan.networkdisk.model.User;
import com.cmpan.networkdisk.utility.MD5;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * ClassName:UserServiceImp
 * Package:com.cmpan.networkdisk.service
 * Description:
 *
 * @Date:2020/7/5 17:16
 * @com.chuangmei
 */
@Service
public class UserServiceImp implements UserService {

    @Resource
    private UserMapper userdao;

    @Override
    public String selectUsername(String username) {

        //调用dao接口查询username
        String name = userdao.selectByUserName(username);

        return name;
    }

    @Override
    public User login(String username, String password) {

        //调用dao接口进行查询
        User user = userdao.selectByUsernameAndPassword(username, MD5.getMD5(password));

        System.out.println("登录操作进行,此处应该打印日志信息!");

        return user;
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public Integer editorUser(User user) {

        //修改用户信息
        Integer count = userdao.updateByPrimaryKeySelective(user);

        return count;
    }

    @Override
    public User selectAll() {

        //查询所有字段
        User user = userdao.selectAll();

        return user;
    }
}
